﻿using GFTest;
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;

namespace GF.Editor
{
    internal sealed class LuaEditorTools
    {

        [MenuItem("GameObject/GFDemo/ReloadLuaScript", false)]
        public static void ReloadLuaScript()
        {
            GameObject go = Selection.activeGameObject;
            if (go.activeInHierarchy)
            {
                Debug.LogWarning("Please close the UIForm first.");
                return;
            }

            LuaNGUIForm form = go.GetComponent<LuaNGUIForm>();
            GameEntry.Lua.LoadScriptInEditor(form.LuaScriptName);
            LuaNGUISubForm[] subForms = form.GetComponentsInChildren<LuaNGUISubForm>(true);
            foreach (LuaNGUISubForm sub in subForms)
            {
                GameEntry.Lua.LoadScriptInEditor(sub.LuaScriptName);
            }
            GameEntry.ObjectPool.ReleaseAllUnused();
            Debug.Log("Reload Lua Script Finish.");
        }

        [MenuItem("GameObject/GFDemo/ReloadLuaScript", true)]
        public static bool IsReloadLuaScript()
        {
            if (Application.isPlaying && GameEntry.Base.EditorResourceMode)
            {
                GameObject go = Selection.activeGameObject;
                if (go != null && go.GetComponent<LuaNGUIForm>() != null)
                {
                    return true;
                }
            }
            return false;
        }
    }
}
